$(document).ready(function(){
	var valueCateShow = "";
	var arrCateValue = $("#cateValue").val().split("|");
	var size = arrCateValue.length;
	arrCateValue.splice(size-1, 1);

	$("#customs_cate li input").each(function(){
		if(arrCateValue.indexOf($(this).val()) > -1){
			valueCateShow += $("#labelCate_" + $(this).val()).html() + ",";
			$(this).prop('checked', true);
		}
	});

	$("#txtCustomsCate").val(valueCateShow);
});

Customs = {
	toogleCate : function(){
		var boxCate = $("#customs_cate");
		if(boxCate.css("display") == "none"){
			boxCate.css("display", "block");
		}
		else{
			boxCate.css("display", "none");	
			Customs.showCateInBox();
		}
	},
	closeCate : function(){
		var boxCate = $("#customs_cate");
		boxCate.css("display", "none");	
		Customs.showCateInBox();
	},
	checkCate : function(val){
		if($("input[value='" + val + "']").is(":checked")){
			$("input[value='" + val + "']").prop('checked', false);			
		}
		else{
			$("input[value='" + val + "']").prop('checked', true);
		}
	},
	deleteAllCate : function(){
		$("#customs_cate li input").each(function(){
			$(this).prop('checked', false);
		});
	},
	showCateInBox : function(){
		var strShow = "";
		$("#customs_cate li input").each(function(){
			if($(this).is(":checked")){
				strShow += $("#labelCate_" + $(this).val()).html() + ",";
			}
		});
		$("#txtCustomsCate").val(strShow);
	},
	customsSearch : function(){
		var customsName = $("#txtSearch").val();
		var customsCate = "";

		$("#customs_cate li input").each(function(){
			if($(this).is(":checked")){
				customsCate += $(this).val() + "|";
			}
		});

		window.location.href = "/thu-tuc-hai-quan/tim-kiem/1?txtSearch=" + customsName + "&txtCustomsCate=" + customsCate;
	}
}